package com.hjtm.easypigfarm.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.hjtm.easypigfarm.R;
import com.hjtm.easypigfarm.utility.Constants;

// zhushe cunlan
public class FragmentPigStore extends Fragment {

    private List<HashMap<String, Object>> mCunLan = new ArrayList<HashMap<String, Object>>();
    /*private final String TITLE_TAG = "title";
    private final String VALUE_TAG = "value";*/
    private Context mContext;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initDatas();
    }

    // TBD
    private void initDatas() {
        mCunLan.clear();
        HashMap<String, Object> map = new HashMap<String, Object>();

        map.put(Constants.TITLE_TAG, "Total");
        map.put(Constants.VALUE_TAG, 1000);
        mCunLan.add(map);

        HashMap<String, Object> map2 = new HashMap<String, Object>();

        map2.put(Constants.TITLE_TAG, "Average");
        map2.put(Constants.VALUE_TAG, 102.1);
        mCunLan.add(map2);

        HashMap<String, Object> map3 = new HashMap<String, Object>();

        map3.put(Constants.TITLE_TAG, "Total2");
        map3.put(Constants.VALUE_TAG, 1500);
        mCunLan.add(map3);

        HashMap<String, Object> map4 = new HashMap<String, Object>();

        map4.put(Constants.TITLE_TAG, "Average2");
        map4.put(Constants.VALUE_TAG, 92.1);
        mCunLan.add(map4);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.chat, null);
        mContext = getActivity();
        if (v != null) {
            GridView zhusheInfo = (GridView) v.findViewById(R.id.gridView1);
            String[] from = {Constants.TITLE_TAG, Constants.VALUE_TAG};
            int[] to = { R.id.item, R.id.value };
            SimpleAdapter adapter = new SimpleAdapter(mContext, mCunLan, R.layout.list_item_value, from, to);
            zhusheInfo.setAdapter(adapter);
        }
        return v;
    }

}
